package com.softtek.base.business.dao.impl;

import com.softtek.base.business.dao.DepartmentInfoDao;
import com.softtek.base.domain.DepartmentInfo;
import com.softtek.base.domain.VO.DepartmentChannelVO;
import com.softtek.base.domain.VO.RegionVO;
import com.softtek.base.sugar.tools.QueryUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author: val.jzp
 */
@Repository("departmentInfoDao")
public class DepartmentInfoDaoImpl implements DepartmentInfoDao {

    private final static Logger logger = LoggerFactory.getLogger(DepartmentInfoDaoImpl.class);

    @PersistenceContext
    private EntityManager entityManager;


    @Override
    public List<DepartmentInfo> findByType(String departmentChannel,String departmentNum) {
        StringBuilder jpql = new StringBuilder(
                "select d from DepartmentInfo d where 1=1 ");
        if (StringUtils.isNotEmpty(departmentChannel)) {
            jpql.append(" and d.departmentChannel = :departmentChannel ");
        }

        if (StringUtils.isNotEmpty(departmentNum)) {
            jpql.append(" and d.departmentNum = :departmentNum ");
        }

        jpql.append(" order by d.departmentInfoId desc");

        logger.info("拼接后的sql为：" + jpql.toString());

        Query query = entityManager.createQuery(jpql.toString(), DepartmentInfo.class);

        if (StringUtils.isNotEmpty(departmentChannel)) {
            query.setParameter("departmentChannel", departmentChannel);
        }

        if (StringUtils.isNotEmpty(departmentNum)) {
            query.setParameter("departmentNum", departmentNum);
        }

        List<DepartmentInfo> departmentInfoList = query.getResultList();
        return departmentInfoList;
    }

    @Override
    public List<DepartmentChannelVO> countChannel() {
        String queryString = "select new com.softtek.base.domain.VO.DepartmentChannelVO(d.departmentChannel) " +
                "from DepartmentInfo d group by d.departmentChannel";


        logger.info("拼接后得到查询语句为:[{}]", queryString);

        TypedQuery<DepartmentChannelVO> typedQuery = this.entityManager.createQuery(queryString, DepartmentChannelVO.class);


        List<DepartmentChannelVO> resultList = typedQuery.getResultList();
        if (resultList != null) {
            logger.info("查询得到数量为：[{}]", resultList.size());
        }
        return resultList;
    }

    @Override
    public List<DepartmentInfo> findByKaSr(String type,String departmentChannel) {

        String queryString = "select d from DepartmentInfo d where d.questionOneAAnswer = :questionOneAAnswer and d.departmentChannel = :departmentChannel";

        if (StringUtils.isNotBlank(type)) {
            queryString = queryString.replaceAll("questionOneAAnswer", type);
        }

        logger.info("拼接后得到查询语句为:[{}]", queryString);

        TypedQuery<DepartmentInfo> typedQuery =entityManager.createQuery(queryString,DepartmentInfo.class);

        if (StringUtils.isNotBlank(type)){
            typedQuery.setParameter(type,"1");
        }

        typedQuery.setParameter("departmentChannel",departmentChannel);

        return typedQuery.getResultList();

    }

    @Override
    public int countByKaSrAndCanUserDepartment(String departmentChannel) {
        Query query = this.entityManager.createQuery("select count(d) from DepartmentInfo d where d.questionTwo is not null and d.departmentChannel = :departmentChannel and d.questionTwo.canUserDepartmentAnswer = :canUserDepartmentAnswer");

        query.setParameter("departmentChannel", departmentChannel);
        query.setParameter("canUserDepartmentAnswer", "1");

        Object obj = query.getSingleResult();

        if (null == obj) {
            return 0;
        } else {
            return Integer.parseInt(obj.toString());
        }
    }

    @Override
    public int countQuestionOneAnswer(String type, String departmentChannel) {

        String queryString = "select count(d) from DepartmentInfo d where d.questionOneAAnswer = :questionOneAAnswer and d.departmentChannel = :departmentChannel";

        if (StringUtils.isNotBlank(type)) {
            queryString = queryString.replaceAll("questionOneAAnswer", type);
        }

        logger.info("拼接后得到查询语句为:[{}]", queryString);

        Query query = this.entityManager.createQuery(queryString);

        if (StringUtils.isNotBlank(type)) {
            query.setParameter(type, "1");
        }

        query.setParameter("departmentChannel", departmentChannel);

        Object obj = query.getSingleResult();

        if (null == obj) {
            return 0;
        } else {
            return Integer.parseInt(obj.toString());
        }
    }

    @Override
    public int countQuestionSevenAnswer(String departmentChannel) {

        String queryString = "select count(d) from DepartmentInfo d where d.questionSevenAnswerOne <> '3' and d.departmentChannel = :departmentChannel";

        logger.info("拼接后得到查询语句为:[{}]", queryString);

        Query query = this.entityManager.createQuery(queryString);

        query.setParameter("departmentChannel", departmentChannel);

        Object obj = query.getSingleResult();

        if (null == obj) {
            return 0;
        } else {
            return Integer.parseInt(obj.toString());
        }
    }

    @Override
    public int countQuestionTwoAnswer(String departmentChannel) {

        String queryString = "select count(d) from DepartmentInfo d where d.questionTwo is not null and d.questionTwo.questionTwoAnswer = :questionTwoAnswer and d.departmentChannel = :departmentChannel";

        logger.info("拼接后得到查询语句为:[{}]", queryString);

        Query query = this.entityManager.createQuery(queryString);

        query.setParameter("departmentChannel", departmentChannel);
        query.setParameter("questionTwoAnswer", "1");

        Object obj = query.getSingleResult();

        if (null == obj) {
            return 0;
        } else {
            return Integer.parseInt(obj.toString());
        }
    }

    @Override
    public int countQuestionFiveAnswer(String questionFiveAnswerA, String questionFiveAnswerB, String departmentChannel) {

        String queryString = "select count(d) from DepartmentInfo d where d.departmentChannel = :departmentChannel and d.questionFiveAnswer = :questionFiveAnswer";

        if (StringUtils.isNotBlank(questionFiveAnswerA)) {
            queryString = queryString + " and d.questionFiveAnswerA = :questionFiveAnswerA";
        }

        if (StringUtils.isNotBlank(questionFiveAnswerB)) {
            queryString = queryString + " and d.questionFiveAnswerB = :questionFiveAnswerB";
        }

        logger.info("拼接后得到查询语句为:[{}]", queryString);

        Query query = this.entityManager.createQuery(queryString);

        query.setParameter("departmentChannel", departmentChannel);
        query.setParameter("questionFiveAnswer", "1");
        if (StringUtils.isNotBlank(questionFiveAnswerA)) {
            query.setParameter("questionFiveAnswerA", "1");
        }
        if (StringUtils.isNotBlank(questionFiveAnswerB)) {
            query.setParameter("questionFiveAnswerB", "1");
        }
        Object obj = query.getSingleResult();

        if (null == obj) {
            return 0;
        } else {
            return Integer.parseInt(obj.toString());
        }
    }

    @Override
    public int countQuestionEightAnswer(String type, String departmentChannel) {
        String queryString = "select count(d) from DepartmentInfo d where d.questionEightAnswer = :questionEightAnswer and d.departmentChannel = :departmentChannel";

        logger.info("拼接后得到查询语句为:[{}]", queryString);

        Query query = this.entityManager.createQuery(queryString);

        query.setParameter("questionEightAnswer",type);

        query.setParameter("departmentChannel", departmentChannel);

        Object obj = query.getSingleResult();

        if (null == obj) {
            return 0;
        } else {
            return Integer.parseInt(obj.toString());
        }
    }

    @Override
    public int countQuestionTwoAnswer(String type, String departmentChannel) {
        String queryString = "select count(d) from DepartmentInfo d where d.questionTwo is not null and d.departmentChannel = :departmentChannel and d.questionTwo.questionTenAnswer = :questionTenAnswer";

        if (StringUtils.isNotBlank(type)) {
            queryString = queryString.replaceAll("questionTenAnswer", type);
        }


        logger.info("拼接后得到查询语句为:[{}]", queryString);

        Query query = this.entityManager.createQuery(queryString);

        query.setParameter("departmentChannel", departmentChannel);

        if (StringUtils.isNotBlank(type)) {
            query.setParameter(type, "1");
        }

        Object obj = query.getSingleResult();

        if (null == obj) {
            return 0;
        } else {
            return Integer.parseInt(obj.toString());
        }
    }

    @Override
    public List<RegionVO> countKaSr() {
        String queryString = "select new com.softtek.base.domain.VO.RegionVO(d.departmentChannel) " +
                "from DepartmentInfo d group by d.departmentChannel";


        logger.info("拼接后得到查询语句为:[{}]", queryString);

        TypedQuery<RegionVO> typedQuery = this.entityManager.createQuery(queryString, RegionVO.class);


        List<RegionVO> resultList = typedQuery.getResultList();
        if (resultList != null) {
            logger.info("查询得到数量为：[{}]", resultList.size());
        }
        return resultList;
    }

    @Override
    public int countEdit() {
        String jpql = "select count(d) from DepartmentInfo d where d.questionTwo <> null";

        Query query = this.entityManager.createQuery(jpql);

        Object obj = query.getSingleResult();

        if (null == obj) {
            return 0;
        } else {
            return Integer.parseInt(obj.toString());
        }
    }

    @Override
    public List<DepartmentInfo> findByType(Integer pageNow, Integer pageSize, String departmentName, String departmentNum, String status) {
        StringBuilder jpql = new StringBuilder(
                "select cic from DepartmentInfo cic where 1=1 ");
        if (StringUtils.isNotEmpty(departmentName)) {
            jpql.append(" and cic.departmentName like :departmentName ");
        }
        if (StringUtils.isNotEmpty(departmentNum)) {
            jpql.append(" and cic.departmentNum like :departmentNum ");
        }

        if (StringUtils.isNotBlank(status)) {
            if (status.equals("1")) {
                jpql.append(" and cic.questionTwo is null");
            } else {
                jpql.append(" and cic.questionTwo is not null");
            }

        }

        jpql.append(" order by cic.departmentInfoId desc");

        logger.info("拼接后的sql为：" + jpql.toString());

        Query query = entityManager.createQuery(jpql.toString(), DepartmentInfo.class);

        if (StringUtils.isNotEmpty(departmentName)) {
            query.setParameter("departmentName", "%" + departmentName + "%");
        }

        if (StringUtils.isNotEmpty(departmentNum)) {
            query.setParameter("departmentNum", "%" + departmentNum + "%");
        }

        if (pageSize > 0 && pageNow > 0) {
            // logger.debug("提交了分页查询信息，pageNow为[" + pageNow + "]，pageSize为[" +
            // pageSize + "]");
            int minLimit = pageSize * (pageNow - 1);
            int maxLimit = pageSize;
            query.setFirstResult(minLimit);
            query.setMaxResults(maxLimit);
        }

        List<DepartmentInfo> departmentInfoList = query.getResultList();
        return departmentInfoList;
    }

    @Override
    public int count(String departmentName, String departmentNum, String status) {
        String jpql = "select count(cic) from DepartmentInfo cic where 1=1";

        if (StringUtils.isNotEmpty(departmentName)) {
            jpql = jpql + " and cic.departmentName like :departmentName ";
        }

        if (StringUtils.isNotEmpty(departmentNum)) {
            jpql = jpql + " and cic.departmentNum like :departmentNum ";
        }

        if (StringUtils.isNotBlank(status)) {
            if (status.equals("1")) {
                jpql = jpql + " and cic.questionTwo is null";
            } else {
                jpql = jpql + " and cic.questionTwo is not null";
            }
        }

        jpql = jpql + " order by cic.departmentInfoId desc";

        logger.info("拼接后的sql为：" + jpql);

        Query query = this.entityManager.createQuery(jpql);

        if (StringUtils.isNotEmpty(departmentName)) {
            query.setParameter("departmentName", "%" + departmentName + "%");
        }
        if (StringUtils.isNotEmpty(departmentNum)) {
            query.setParameter("departmentNum", "%" + departmentNum + "%");
        }
        Object obj = query.getSingleResult();

        if (null == obj) {
            return 0;
        } else {
            return Integer.parseInt(obj.toString());
        }
    }


    // ******************************************************************************
    // ********************************* CRUD START *********************************
    // ******************************************************************************

    public Map<String, Object> getSearchCondition(Map<String, String> queryHash) {

        Map<String, Object> conditionHash = new HashMap<String, Object>();
        if (queryHash == null) {
            return conditionHash;
        }

        String interviewUserName = queryHash.get("interviewUserName");
        if (!StringUtils.isEmpty(interviewUserName)) {
            conditionHash.put("interviewUserName = ?{paramIndex} ", interviewUserName);
        }

        String departmentName = queryHash.get("departmentName");
        if (!StringUtils.isEmpty(departmentName)) {
            conditionHash.put("departmentName like ?{paramIndex} ", "%" + departmentName + "%");
        }

        String departmentNum = queryHash.get("departmentNum");
        if (!StringUtils.isEmpty(departmentNum)) {
            conditionHash.put("departmentNum like ?{paramIndex} ", "%" + departmentNum + "%");
        }

        /*String String = queryHash.get("String");
        if (!StringUtils.isEmpty(String)) {
			conditionHash.put("String like ?{paramIndex} ", "%" + String + "%");
		}
		Integer Integer = TypeConvertUtils.StringToInteger(queryHash.get("Integer"));
		if (Integer != null && Integer > -1) {
			conditionHash.put("Integer = ?{paramIndex} ", Integer);
		}
		Date Date = TypeConvertUtils.StringToDate(queryHash.get("Date"));
		if (Date != null) {
			conditionHash.put("Date >= ?{paramIndex} ", Date);
		}*/

        return conditionHash;
    }


    @Override
    public Long totalRecord(Map<String, String> queryHash) {

        Map<String, Object> conditions = getSearchCondition(queryHash);
        TypedQuery<Long> typedQuery = QueryUtils.getTypedQueryByCondition("select count(a) from DepartmentInfo a ", conditions, "", entityManager, Long.class);
        return typedQuery.getSingleResult();
    }

    @Override
    public List<DepartmentInfo> findList(Integer pageNow, Integer pageSize, String sqlOrder, Map<String, String> queryHash) {

        if (StringUtils.isEmpty(sqlOrder)) {
            sqlOrder = "order by a.departmentInfoId desc ";
        }

        Map<String, Object> conditions = getSearchCondition(queryHash);
        TypedQuery<DepartmentInfo> typedQuery = QueryUtils.getTypedQueryByCondition("select a from DepartmentInfo a ", conditions, sqlOrder, entityManager, DepartmentInfo.class);
        // 判断是否需要分页，并提交分页方法
        if (pageSize > 0 && pageNow > 0) {
            logger.debug("提交了分页查询信息，pageNow为[" + pageNow + "]，pageSize为[" + pageSize + "]");
            int minLimit = pageSize * (pageNow - 1);
            int maxLimit = pageSize;
            typedQuery.setFirstResult(minLimit).setMaxResults(maxLimit);
        }
        // 返回查询结果
        return typedQuery.getResultList();
    }

    @Override
    public DepartmentInfo findModel(Long departmentInfoId) {
        return entityManager.find(DepartmentInfo.class, departmentInfoId);
    }

    @Override
    public Integer add(DepartmentInfo departmentInfo) {
        entityManager.persist(departmentInfo);
        logger.info("DepartmentInfoDaoImpl添加departmentInfo成功！");
        return 1;
    }

    @Override
    public Integer update(DepartmentInfo departmentInfo) {
        DepartmentInfo existDepartmentInfo = entityManager.find(DepartmentInfo.class, departmentInfo.getDepartmentInfoId());
        //部门，访问员信息
        existDepartmentInfo.setQuestionTwo(departmentInfo.getQuestionTwo());
        if (StringUtils.isNotBlank(departmentInfo.getInterviewUserName())) {
            existDepartmentInfo.setInterviewUserName(departmentInfo.getInterviewUserName());
        }
        if (StringUtils.isNotBlank(departmentInfo.getDepartmentChannel())) {
            existDepartmentInfo.setDepartmentChannel(departmentInfo.getDepartmentChannel());
        }
        existDepartmentInfo.setInterviewDate(departmentInfo.getInterviewDate());
        existDepartmentInfo.setEnterDepartmentDate(departmentInfo.getEnterDepartmentDate());
        existDepartmentInfo.setLeaveDepartmentDate(departmentInfo.getLeaveDepartmentDate());
        if (StringUtils.isNotBlank(departmentInfo.getDepartmentNum())) {
            existDepartmentInfo.setDepartmentNum(departmentInfo.getDepartmentNum());
        }
        if (StringUtils.isNotBlank(departmentInfo.getDepartmentName())) {
            existDepartmentInfo.setDepartmentName(departmentInfo.getDepartmentName());
        }
        if (StringUtils.isNotBlank(departmentInfo.getDepartmentAddress())) {
            existDepartmentInfo.setDepartmentAddress(departmentInfo.getDepartmentAddress());
        }
        //问题答案图片Q1
        existDepartmentInfo.setQuestionOneAAnswer(departmentInfo.getQuestionOneAAnswer());
        existDepartmentInfo.setQuestionOneAPrice(departmentInfo.getQuestionOneAPrice());
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneAImageUrl())) {
            existDepartmentInfo.setQuestionOneAImageUrl(departmentInfo.getQuestionOneAImageUrl());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneAImageUrl2())) {
            existDepartmentInfo.setQuestionOneAImageUrl2(departmentInfo.getQuestionOneAImageUrl2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneAImageUrl3())) {
            existDepartmentInfo.setQuestionOneAImageUrl3(departmentInfo.getQuestionOneAImageUrl3());
        }

        existDepartmentInfo.setQuestionOneBAnswer(departmentInfo.getQuestionOneBAnswer());
        existDepartmentInfo.setQuestionOneBPrice(departmentInfo.getQuestionOneBPrice());
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneBImageUrl())) {
            existDepartmentInfo.setQuestionOneBImageUrl(departmentInfo.getQuestionOneBImageUrl());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneBImageUrl2())) {
            existDepartmentInfo.setQuestionOneBImageUrl2(departmentInfo.getQuestionOneBImageUrl2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneBImageUrl3())) {
            existDepartmentInfo.setQuestionOneBImageUrl3(departmentInfo.getQuestionOneBImageUrl3());
        }
        existDepartmentInfo.setQuestionOneCAnswer(departmentInfo.getQuestionOneCAnswer());
        existDepartmentInfo.setQuestionOneCPrice(departmentInfo.getQuestionOneCPrice());

        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneCImageUrl())) {
            existDepartmentInfo.setQuestionOneCImageUrl(departmentInfo.getQuestionOneCImageUrl());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneCImageUrl2())) {
            existDepartmentInfo.setQuestionOneCImageUrl2(departmentInfo.getQuestionOneCImageUrl2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneCImageUrl3())) {
            existDepartmentInfo.setQuestionOneCImageUrl3(departmentInfo.getQuestionOneCImageUrl3());
        }

        existDepartmentInfo.setQuestionOneDAnswer(departmentInfo.getQuestionOneDAnswer());
        existDepartmentInfo.setQuestionOneDPrice(departmentInfo.getQuestionOneDPrice());

        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneDImageUrl())) {
            existDepartmentInfo.setQuestionOneDImageUrl(departmentInfo.getQuestionOneDImageUrl());
        }

        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneDImageUrl2())) {
            existDepartmentInfo.setQuestionOneDImageUrl2(departmentInfo.getQuestionOneDImageUrl2());
        }

        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneDImageUrl3())) {
            existDepartmentInfo.setQuestionOneDImageUrl3(departmentInfo.getQuestionOneDImageUrl3());
        }

        existDepartmentInfo.setQuestionOneEAnswer(departmentInfo.getQuestionOneEAnswer());
        existDepartmentInfo.setQuestionOneEPrice(departmentInfo.getQuestionOneEPrice());

        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneEImageUrl())) {
            existDepartmentInfo.setQuestionOneEImageUrl(departmentInfo.getQuestionOneEImageUrl());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneEImageUrl2())) {
            existDepartmentInfo.setQuestionOneEImageUrl2(departmentInfo.getQuestionOneEImageUrl2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneEImageUrl3())) {
            existDepartmentInfo.setQuestionOneEImageUrl3(departmentInfo.getQuestionOneEImageUrl3());
        }


        existDepartmentInfo.setQuestionOneFAnswer(departmentInfo.getQuestionOneFAnswer());
        existDepartmentInfo.setQuestionOneFPrice(departmentInfo.getQuestionOneFPrice());

        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneFImageUrl())) {
            existDepartmentInfo.setQuestionOneFImageUrl(departmentInfo.getQuestionOneFImageUrl());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneFImageUrl3())) {
            existDepartmentInfo.setQuestionOneFImageUrl3(departmentInfo.getQuestionOneFImageUrl3());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneFImageUrl2())) {
            existDepartmentInfo.setQuestionOneFImageUrl2(departmentInfo.getQuestionOneFImageUrl2());
        }

        existDepartmentInfo.setQuestionOneGAnswer(departmentInfo.getQuestionOneGAnswer());
        existDepartmentInfo.setQuestionOneGPrice(departmentInfo.getQuestionOneGPrice());

        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneGImageUrl())) {
            existDepartmentInfo.setQuestionOneGImageUrl(departmentInfo.getQuestionOneGImageUrl());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneGImageUrl2())) {
            existDepartmentInfo.setQuestionOneGImageUrl2(departmentInfo.getQuestionOneGImageUrl2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneGImageUrl3())) {
            existDepartmentInfo.setQuestionOneGImageUrl3(departmentInfo.getQuestionOneGImageUrl3());
        }


        existDepartmentInfo.setQuestionOneHAnswer(departmentInfo.getQuestionOneHAnswer());
        existDepartmentInfo.setQuestionOneHPrice(departmentInfo.getQuestionOneHPrice());

        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneHImageUrl())) {
            existDepartmentInfo.setQuestionOneHImageUrl(departmentInfo.getQuestionOneHImageUrl());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneHImageUrl2())) {
            existDepartmentInfo.setQuestionOneHImageUrl2(departmentInfo.getQuestionOneHImageUrl2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionOneHImageUrl3())) {
            existDepartmentInfo.setQuestionOneHImageUrl3(departmentInfo.getQuestionOneHImageUrl3());
        }

        //问题答案图片Q3
        existDepartmentInfo.setQuestionThreeAnswer(departmentInfo.getQuestionThreeAnswer());
        if (StringUtils.isNotBlank(departmentInfo.getQuestionThreeImageUrl())) {
            existDepartmentInfo.setQuestionThreeImageUrl(departmentInfo.getQuestionThreeImageUrl());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionThreeImageUrl2())) {
            existDepartmentInfo.setQuestionThreeImageUrl2(departmentInfo.getQuestionThreeImageUrl2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionThreeImageUrl3())) {
            existDepartmentInfo.setQuestionThreeImageUrl3(departmentInfo.getQuestionThreeImageUrl3());
        }

        //问题答案图片Q4
        existDepartmentInfo.setQuestionFourAnswer(departmentInfo.getQuestionFourAnswer());
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFourImageUrl())) {
            existDepartmentInfo.setQuestionFourImageUrl(departmentInfo.getQuestionFourImageUrl());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFourImageUrl2())) {
            existDepartmentInfo.setQuestionFourImageUrl2(departmentInfo.getQuestionFourImageUrl2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFourImageUrl3())) {
            existDepartmentInfo.setQuestionFourImageUrl3(departmentInfo.getQuestionFourImageUrl3());
        }
        //问题答案图片Q5
        existDepartmentInfo.setQuestionFiveAnswer(departmentInfo.getQuestionFiveAnswer());
        existDepartmentInfo.setQuestionFiveAnswerA(departmentInfo.getQuestionFiveAnswerA());
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFiveImageUrlA())) {
            existDepartmentInfo.setQuestionFiveImageUrlA(departmentInfo.getQuestionFiveImageUrlA());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFiveImageUrlA2())) {
            existDepartmentInfo.setQuestionFiveImageUrlA2(departmentInfo.getQuestionFiveImageUrlA2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFiveImageUrlA3())) {
            existDepartmentInfo.setQuestionFiveImageUrlA3(departmentInfo.getQuestionFiveImageUrlA3());
        }
        existDepartmentInfo.setQuestionFiveAnswerB(departmentInfo.getQuestionFiveAnswerB());
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFiveImageUrlB())) {
            existDepartmentInfo.setQuestionFiveImageUrlB(departmentInfo.getQuestionFiveImageUrlB());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFiveImageUrlB2())) {
            existDepartmentInfo.setQuestionFiveImageUrlB2(departmentInfo.getQuestionFiveImageUrlB2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFiveImageUrlB3())) {
            existDepartmentInfo.setQuestionFiveImageUrlB3(departmentInfo.getQuestionFiveImageUrlB3());
        }

        existDepartmentInfo.setQuestionFiveAnswerC(departmentInfo.getQuestionFiveAnswerC());
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFiveImageUrlC())) {
            existDepartmentInfo.setQuestionFiveImageUrlC(departmentInfo.getQuestionFiveImageUrlC());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFiveImageUrlC2())) {
            existDepartmentInfo.setQuestionFiveImageUrlC2(departmentInfo.getQuestionFiveImageUrlC2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionFiveImageUrlC3())) {
            existDepartmentInfo.setQuestionFiveImageUrlC3(departmentInfo.getQuestionFiveImageUrlC3());
        }
        //问题答案图片Q6
        existDepartmentInfo.setQuestionSixAnswer(departmentInfo.getQuestionSixAnswer());
        existDepartmentInfo.setQuestionSixAnswerSelf(departmentInfo.getQuestionSixAnswerSelf());
        if (StringUtils.isNotBlank(departmentInfo.getQuestionSixAnswerImage())) {
            existDepartmentInfo.setQuestionSixAnswerImage(departmentInfo.getQuestionSixAnswerImage());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionSixAnswerImage2())) {
            existDepartmentInfo.setQuestionSixAnswerImage2(departmentInfo.getQuestionSixAnswerImage2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionSixAnswerImage3())) {
            existDepartmentInfo.setQuestionSixAnswerImage3(departmentInfo.getQuestionSixAnswerImage3());
        }
        //问题答案图片Q7
        existDepartmentInfo.setQuestionSevenAnswerOne(departmentInfo.getQuestionSevenAnswerOne());
        existDepartmentInfo.setQuestionSevenAnswerTwo(departmentInfo.getQuestionSevenAnswerTwo());
        existDepartmentInfo.setQuestionSevenAnswerTwoSelf(departmentInfo.getQuestionSevenAnswerTwoSelf());
        if (StringUtils.isNotBlank(departmentInfo.getQuestionSevenAnswerImageUrl())) {
            existDepartmentInfo.setQuestionSevenAnswerImageUrl(departmentInfo.getQuestionSevenAnswerImageUrl());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionSevenAnswerImageUrl2())) {
            existDepartmentInfo.setQuestionSevenAnswerImageUrl2(departmentInfo.getQuestionSevenAnswerImageUrl2());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionSevenAnswerImageUrl3())) {
            existDepartmentInfo.setQuestionSevenAnswerImageUrl3(departmentInfo.getQuestionSevenAnswerImageUrl3());
        }
        //问题答案图片Q8
        if (StringUtils.isNotBlank(departmentInfo.getQuestionSevenAnswerOne()) && departmentInfo.getQuestionSevenAnswerOne().equals("3")) {
            existDepartmentInfo.setQuestionEightAnswer("e");
        } else {
            existDepartmentInfo.setQuestionEightAnswer(departmentInfo.getQuestionEightAnswer());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionEightImageUrlA())) {
            existDepartmentInfo.setQuestionEightImageUrlA(departmentInfo.getQuestionEightImageUrlA());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionEightImageUrlB())) {
            existDepartmentInfo.setQuestionEightImageUrlB(departmentInfo.getQuestionEightImageUrlB());
        }
        if (StringUtils.isNotBlank(departmentInfo.getQuestionEightImageUrlC())) {
            existDepartmentInfo.setQuestionEightImageUrlC(departmentInfo.getQuestionEightImageUrlC());
        }
        //问题答案图片Q9
        if (StringUtils.isNotBlank(departmentInfo.getQuestionSevenAnswerOne()) && departmentInfo.getQuestionSevenAnswerOne().equals("3")) {
            existDepartmentInfo.setQuestionNineAnswer("3");
        } else {
            existDepartmentInfo.setQuestionNineAnswer(departmentInfo.getQuestionNineAnswer());
        }


        return 1;
    }


    // ******************************************************************************
    // ********************************** CRUD END **********************************
    // ******************************************************************************
}